import javafx.application.Preloader;

import java.util.Random;
import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n1 = sc.nextInt();
        int n2 = sc.nextInt();

        while (n2 != 0){
            int tmp = n1 % n2;
            n1 = n2;
            n2 = tmp;
        }
        System.out.println(n1);
    }
    public static void main8(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        int n = scanner.nextInt();
//        //0000 0010
//        for (int i = 31; i >= 1 ; i-=2) {
//            System.out.print(((n>>>i) & 1) + " " );
//        }
//        System.out.println();
//        for (int i = 30; i >= 0 ; i-=2) {
//            System.out.print(((n>>>i) & 1) + " " );
//        }
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();

        for (int i = 31; i >= 1; i -= 2) {
            if (((num >> i) & 1) == 1){
                System.out.print("1 ");
            }else{
                System.out.print("0 ");
            }
        }
        System.out.println();
        for (int i = 30; i >= 0; i -= 2) {
            if (((num >> i) & 1) == 1){
                System.out.print("1 ");
            }else{
                System.out.print("0 ");
            }
        }
    }
    public static void main7(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = 3;
        System.out.println("请输入你的密码：");
        while (count != 0){
            String password = sc.nextLine();
            if (password.equals("123")){
                System.out.println("登陆成功");
                break;
            }else{
                count--;
                System.out.println("密码错误，请重新输入");
            }
        }

//        int password = 123;
//        int count = 3;
//
//        Scanner sc = new Scanner(System.in);
//        while (true){
//            if (count == 0) {
//                System.out.println("密码错误三次，程序退出！！");
//                break;
//            }
//            System.out.println("请输入你的密码：");
//            int myPassword = sc.nextInt();
//            if (myPassword == password){
//                System.out.println("密码正确");
//                break;
//            }else{
//                System.out.println("密码错误,请重新输入");
//                count--;
//
//            }
//        }
    }
    public static void main6(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入一个数字");
        int n = sc.nextInt();

        while (n != 0){
            System.out.println(n % 10);
            n /= 10;
        }
    }

    public static void main5(String[] args) {
        Random random = new Random();
        int guessNum = random.nextInt(100);//[0,100);

        Scanner sc = new Scanner(System.in);
        while (true){
            System.out.println("请输入要猜的数字：");
            int num = sc.nextInt();
            if (guessNum < num) {
                System.out.println("猜大了");
            }else if (guessNum > num){
                System.out.println("猜小了");
            }else {
                System.out.println("猜对了");
                break;
            }
        }
    }
    public static void main4(String[] args) {
        double ans = 0.0;
        int flg = 1;
        for (int i = 1; i <= 100; i++) {
            ans += 1.0 / i * flg;
            flg *= -1;
        }

        System.out.println(ans);
    }
    public static int num9CountS(int n){
        int c = 0;
        for (int i = 1;i <= n;i++){
            int tmp = i;
            while (tmp != 0){
                if (tmp % 10 == 9){
                    c++;
                }
                tmp /= 10;
            }
        }
        return c;
    }
    public static void main3(String[] args) {
        System.out.println(num9CountS(100));
    }

    public static int fac(int num){
        int sum = 1;
        for (int i = 1; i <= num; i++) {
            sum *= i;
        }
        return sum;
    }

    public static int facSum(int n){
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += fac(i);
        }
        return sum;
    }
    public static void main2(String[] args) {
        System.out.println(fac(4));
        System.out.println(facSum((4)));

        System.out.println(Integer.MAX_VALUE);
    }


    public static void main1(String[] args) {
        System.out.println("1111");


        System.out.println(Add(1,2));
    }

    public static int Add (int a,int b){
        return a + b;
    }

}
